package com.capinfo.accounting.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.capinfo.accumulation.model.accounting.mybist.GB_JZPZXX;
import com.capinfo.accumulation.parameter.accounting.DataGrid;
import com.capinfo.accumulation.service.accounting.mybits.GB_JZPZXXServiceI;
import com.capinfo.accumulation.service.accounting.mybits.HZJZPZServiceI;
import com.capinfo.accumulation.util.NumberToCN;
import com.google.gson.Gson;
@Controller
@RequestMapping("/business/accounting/pingzhengcx")
public class PZCXController {

	
	@Autowired
	HZJZPZServiceI hZJZPZService;
	
	@Autowired
	GB_JZPZXXServiceI gB_JZPZXXServiceI;
	
	@RequestMapping("/dataGrid.shtml")
	@ResponseBody
	public DataGrid dataGrid(@RequestParam  Map param) {
		return hZJZPZService.findbyByGrid(param);
	}
	
	@RequestMapping(value="/pzlb")  
	@ResponseBody  
	public void hsdw (HttpServletRequest request,HttpServletResponse response) throws IOException  {
		response.setHeader("Content-type", "text/html;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		 Gson gson = new Gson();
		   Map map = new HashMap();
		   List<Map<String,Object>>pzlb= hZJZPZService.pzlb(map);
		   PrintWriter pw;
		   pw = response.getWriter();
		   pw.write(gson.toJson(pzlb));
	   }
	
	@RequestMapping(value="/ywlx")  
	@ResponseBody  
	public List ywlx (HttpServletRequest request,HttpServletResponse response) throws IOException  {
		   Map map = new HashMap();
		   List<Map<String,Object>>ywlx= hZJZPZService.ywlx(map);
		   return ywlx;
	   }
	
	@RequestMapping(value="/zd")  
	@ResponseBody  
	public List zd (HttpServletRequest request,HttpServletResponse response) throws IOException  {
		   Map map = new HashMap();
		   List<Map<String,Object>>zd= hZJZPZService.zd(map);
		   return zd;
	   }
	

	@RequestMapping(value="/fh")  
	@ResponseBody  
	public List fh (HttpServletRequest request,HttpServletResponse response) throws IOException  {
		   Map map = new HashMap();
		   List<Map<String,Object>>fh= hZJZPZService.fh(map);
		   return fh;
	   }
	
	@RequestMapping("/search.shtml")
	public String search() {
		return "/business/accounting/pingzhengcx/PZCX";
	}
	
	@RequestMapping("/viewPage.shtml")
	public String viewPage(HttpServletRequest request,Map map) {
		String JZRQ = request.getParameter("JZRQ");
		String XSPZH = request.getParameter("XSPZH");
		map.put("JZRQ_EQ_DATE_yyyyMMdd", JZRQ);
 		map.put("JZRQ_END_DATE_yyyyMMdd", JZRQ);
		map.put("XSPZH_EQ_STR", XSPZH);
		DataGrid dd= this.gB_JZPZXXServiceI.findbyByGrid(map);
		List list = dd.getRows();
		Map mmm=new HashMap();
		List list1 = new ArrayList();
		double j= 0;
		double d= 0;
		   for(int i=0; i<list.size(); i++)    {   
			   GB_JZPZXX gb=   (GB_JZPZXX) list.get(i); 
			   j+=gb.getJFFSE();
			   d+=gb.getDFFSE();
		   } 
	        String nj = NumberToCN.number2CNMontrayUnit(new BigDecimal(j));
	        String nd = NumberToCN.number2CNMontrayUnit(new BigDecimal(d));
		   mmm.put("DFFSE", d);
		   mmm.put("JFFSE", j);
		   mmm.put("dDFFSE", nd);
		   mmm.put("dJFFSE", nj);
		   list1.add(mmm);
		request.setAttribute("list1",list1);   
		request.setAttribute("ddList",list);
		Map mm=new HashMap();
		mm.put("XSPZH", XSPZH);
		mm.put("JZRQ", JZRQ);
		List<Map<String, Object>> HZ=hZJZPZService.xianshihsdw(mm);
		request.setAttribute("HZ", HZ);
		return "/business/accounting/pingzhengcx/chakan";
	}
	
	@RequestMapping("/shangchuanPagePage.shtml")
	public String shangchuanPagePage(HttpServletRequest request,Map map) {
		return "/business/accounting/pingzhengcx/shangchuan";
   }
}